
function message() {
    var _this = this;
    _this.page;
    _this.page_size = 10;

    _this.registerParams;


    _this.init = function(page){
        _this.page = page;
        _this.registerParams = {}
        _this.open_window = 0;
        _this.initTable();

        $("#message_status span").click(function () {
            $(this).siblings("span").removeClass("active");
            $(this).addClass("active");
            var value = $(this).attr("data-value");
            $("input[name=messageStatus]").val(value);
            _this.page.goPage(1);
        });

        $("#message_table").on("click", ".agree_yes", function () {
            if($(this).attr("href")){
                var id = $(this).attr("messageid");
                var pid = $(this).attr("pid");
                var params = {"id": id, "pid": pid, "isTrue": "true"};
                var url = appPath + "/admin/dispose_message";
                var data = _this.ajax(url, params);
                if(data['code'] == 10000){
                    layer.msg("处理成功");
                    _this.page.refresh_cur_page();
                }
            }
        });
        $("#message_table").on("click", ".agree_no", function () {
            if($(this).attr("href")){
                var id = $(this).attr("messageid");
                var params = {"id": id};
                var url = appPath + "/admin/dispose_message";
                var data = _this.ajax(url, params);
                if(data['code'] == 10000){
                    layer.msg("处理成功");
                    _this.page.refresh_cur_page();
                }
            }
        });

        //同意变更公司
        $("#message_table").on("click", ".move_yes", function () {
            if($(this).attr("href")){
                var messageId = $(this).attr("messageid");
                var companyId = $(this).attr("companyId");
                var userId = $(this).attr("userId");
                var userName = $(this).attr("userName");
                _this.registerParams = {"messageId": messageId, "companyId": companyId, "userId": userId,'userName':userName};
                /*var url = appPath + "/move_to_new_company";
                var data = _this.ajax(url, params);
                if(data['code'] == 10000){
                    layer.msg("处理成功");
                    _this.page.refresh_cur_page();
                }*/
                // 弹窗-选择部门
                layer.open({
                    type: 2,
                    title: '请为该用户选择部门',
                    shadeClose: false,				//true点击遮罩层关闭
                    shade: 0.3,					//遮罩层背景
                    maxmin: true, 					// 开启最大化最小化按钮
                    area: ['300px', '60%'],		//弹出层大小
                    scrollbar: false,				//false隐藏滑动块
                    content: [appPath + '/domain/selectDept?companyId=' + companyId + '&userId='+userId + '&type=move', 'yes']
                });
            }
        });
        $("#message_table").on("click", ".move_no", function () {
            if($(this).attr("href")){
                var messageId = $(this).attr("messageid");
                var params = {"messageId": messageId};
                var url = appPath + "/move_to_new_company";
                var data = _this.ajax(url, params);
                if(data['code'] == 10000){
                    layer.msg("处理成功");
                    _this.page.refresh_cur_page();
                }
            }
        });

        //同意用户注册(管理员必须为新注册的用户选择部门)
        $("#message_table").on("click", ".register_yes", function () {
            if($(this).attr("href")){
                var messageId = $(this).attr("messageid");
                var companyId = $(this).attr("companyId");
                var userId = $(this).attr("userId");
                var userName = $(this).attr("userName");
                _this.registerParams = {"messageId": messageId, "companyId": companyId, "userId": userId,'userName':userName};
                // 弹窗-选择部门
                layer.open({
                    type: 2,
                    title: '请为该用户选择部门',
                    shadeClose: false,				//true点击遮罩层关闭
                    shade: 0.3,					//遮罩层背景
                    maxmin: true, 					// 开启最大化最小化按钮
                    area: ['300px', '60%'],		//弹出层大小
                    scrollbar: false,				//false隐藏滑动块
                    content: [appPath + '/domain/selectDept?companyId=' + companyId + '&userId='+userId + '&type=register', 'yes']
                });
            }
        });

        $("#message_table").on("click", ".register_no", function () {
            if($(this).attr("href")){
                var messageId = $(this).attr("messageid");
                var userId = $(this).attr("userId");
                _this.registerParams = {"messageId": messageId, "userId": userId};
                var url = appPath + "/domain/register_to_company";
                var data = _this.ajax(url, _this.registerParams);
                if(data['code'] == 10000){
                    layer.msg("处理成功");
                    // 刷新
                    _this.initTable();
                }
            }
        });

        $("#message_table").on("click", ".a-publish", function () {
            var id = $(this).attr("messageid");
            var params = {"id": id};
            var url = appPath + "/message/updateStatus";
            var data = _this.ajax(url, params);
            if(data['code'] == 10000){
                layer.msg("处理成功");
                _this.page.refresh_cur_page();
                // 刷新未读信息数据
                _this.refresh_ReadMessageCount();
            }
        });
    };

    _this.refresh_ReadMessageCount = function(){
        var mycookie = document.cookie;

        var messageCookie = mycookie.substring(mycookie.indexOf("notReadMessageCount=") + "notReadMessageCount=".length, mycookie.length);
        var messageCookieCount = messageCookie.indexOf(";") != -1 ? messageCookie.substring(0, messageCookie.indexOf(";")) : messageCookie;
        if(messageCookieCount > 0){
            document.getElementById("curren_message_count").innerHTML = messageCookieCount;
            document.getElementById("curren_message_count").style.display = 'block';
        }else{
            document.getElementById("curren_message_count").style.display = 'none';
        }
    }

    /**
     * 审核实现
     */
    _this.registerAuditing = function(departmentId, departmentName,type){
        _this.registerParams['departmentId'] = departmentId;
        _this.registerParams['departmentName'] = departmentName;
        var url = "";
        if("move" == type){
            url = appPath + "/move_to_new_company";
        }else{
            url = appPath + '/domain/register_to_company';
        }

        $.ajax({
            url: url,
            async: false,
            type: 'post',
            data: _this.registerParams,
            success: function(data){
                var result = data.code;
                if(result == 10000){
                    layer.msg("处理成功");
                    layer.closeAll();
                    // 刷新
                    _this.initTable();
                }else{
                    layer.alert('操作失敗', {icon: 2,  skin: 'layer-ext-moon'});
                }
            }
        });

    }

    _this.initTable = function(){
        var list_url = appPath + "/message/list";
        _this.page.init("message_form", list_url, "message_table", "message_page", 1, _this.page_size);
        _this.page.goPage(1);
        _this.page.list = function(dataList){
            var len = dataList.length;
            var inner = "", item;
            var messageContent = '';
            // 组装数据
            for(var i=0; i< len; i++) {
                item = dataList[i];
                inner += '<tr>';
                inner += '<td>' + (i+1) + '</td>';
                inner += '<td>'+ item['messageTitle'] + '</td>';
                messageContent = item['messageContent'];
                inner += '<td>'+ messageContent.split('<div>')[0] + '</td>';
                inner += '<td>'+ item['sendName'] + '</td>';
                inner += '<td>'+ TimeUtil.longMsTimeConvertToDateTime(item['createTime']) + '</td>';
                var messageStatus = item['messageStatus'] == "1" ? "未读" : "已读";
                inner += '<td>'+ messageStatus + '</td>';

                inner += '<td><a href="javascript:void(0);" class="a';
                if(item['messageStatus'] == "1"){
                    inner += ' a-publish" messageid="'+ item['id'] + '">标为已读</a>';
                }else{
                    inner += '">已预览</a>';
                }
                if(messageContent.split('<div>').length > 1){
                    var btnstr = messageContent.split('<div>')[1].replace('</div>','');
                    inner += btnstr;
                }
                inner += '</td></tr>';
            }
            return inner;
        }
    };

    _this.ajax = function(url, param, type) {
        var result;
        $.ajax({
            url : url,
            async : false,
            type : 'post',
            data : param,
            success : function(data) {
                result = data;
            }
        });
        return result;
    };


}
var myMessage = new message();


function feedback() {
    var _this = this;
    _this.page;
    _this.page_size = 10;

    _this.init = function(page){
        _this.page = page;
        _this.initTable();

        $("#problem_type span").click(function () {
            $(this).siblings("span").removeClass("active");
            $(this).addClass("active");
            var value = $(this).attr("data-value");
            $("input[name=problemType]").val(value);
            _this.page.goPage(1);
        });
    };

    _this.initTable = function(){
        var list_url = appPath + "/feedback/list";
        _this.page.init("feedback_form", list_url, "feedback_table", "feedback_page", 1, _this.page_size);
        _this.page.goPage(1);
        _this.page.list = function(dataList){
            var len = dataList.length;
            var inner = "", item;
            // 组装数据
            for(var i=0; i< len; i++) {
                item = dataList[i];
                inner += '<tr>';
                inner += '<td>' + (i+1) + '</td>';
                inner += '<td><div style="word-break: break-all;">';
                inner += '<textarea class="feedback content" readonly>';
                inner += item['content'];
                inner += '</textarea></div></td>';
                inner += '<td>'+ item['problemType'] + '</td>';
                inner += '<td>'+ TimeUtil.longMsTimeConvertToDateTime(item['createTime']) + '</td>';
                inner += '<td>';
                var attachmentLMap = item['attachmentLMap'];
                for(var j=0; j< attachmentLMap.length; j++) {
                    var id = attachmentLMap[j]['fileId'];
                    var name = attachmentLMap[j]['fileName'];
                    inner += '<a target="_blank" href="' + id + '" class="a a-attachment">' + name + '</a>';
                }
                inner += '</td>';
                inner += '<td>';
                var problemStatus = item['problemStatus'];
                if(1==problemStatus){
                    inner += '未处理';
                }else if(2==problemStatus){
                    inner += '已处理';
                }else{
                    inner += '不处理';
                }
                inner += '</td>';
                inner += '<td>';
                inner += '<a href="javascript:feedback.feedbackRely(\'' + item['id'] + '\');" class="a a-view">查看回复</a>';
                inner += '</td>';
                inner += '</tr>';
            }
            return inner;
        }
    };

    _this.feedbackRely = function (feedback_id) {
        var url = appPath + "/feedback/feedback_reply?feedback_id=" + feedback_id;
        var data = _this.ajax(url);
        if(data['code'] == 10000){
            var result = data['result'];
            layer.alert(result);
        }else{
            layer.alert(data['message']);
        }
    };

    _this.ajax = function(url, param, type) {
        var result;
        $.ajax({
            url : url,
            async : false,
            type : 'post',
            data : param,
            success : function(data) {
                result = data;
            }
        });
        return result;
    };
}
var feedback = new feedback();